<template>
  <div>
    <button @click="getApi">发送get请求</button>
    <button @click="postApi">发送post请求</button><br />
    <input type="text" v-model="author" /><br />
    <input type="text" v-model="title" /><br />
    <button @click="postApi1">提交数据</button>
    <br />
    <form>
      <input type="text" v-model="author" /><br />
      <input type="text" v-model="title" /><br />
      <input type="submit" value="提交" @click.prevent="celData" />
    </form>
  </div>
</template>

<script>
import { testGet, testPost } from "../ajax/api";
export default {
  name: "",
  props: [""],
  data() {
    return {
      author: "",
      title: ""
    };
  },

  components: {},

  computed: {},

  beforeMount() {},

  mounted() {},

  methods: {
    getApi() {
      const url = "/posts";
      testGet(url, { id: 10 });
    },
    postApi() {
      const url = "/posts";
      const obj = {
        title: "xx",
        author: "uu"
      };
      testPost(url, obj);
    },
    postApi1() {
      const url = "/posts";
      const obj = {
        title: this.title,
        author: this.author
      };
      testPost(url, obj);
    },
    celData() {
      const url = "/posts";
      const obj = {
        title: this.title,
        author: this.author
      };
      testPost(url, obj);
    }
  },

  watch: {}
};
</script>
<style lang="" scoped></style>
